package com.si.sea_island.utils;//package com.si.sea_island.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import com.google.gson.Gson;
//import okhttp3.*;
//import org.apache.commons.codec.binary.Base64;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.RequestEntity;
//import org.springframework.web.client.RestTemplate;
//import org.springframework.web.util.UriComponentsBuilder;
//
//import javax.crypto.Cipher;
//import javax.crypto.KeyGenerator;
//import javax.crypto.SecretKey;
//import javax.crypto.spec.SecretKeySpec;
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.net.URI;
//import java.net.URLEncoder;
//import java.security.NoSuchAlgorithmException;
//import java.util.HashMap;
//import java.util.Map;
//
//
//public class AESUtils {
//    @Autowired
//    RestTemplate restTemplate;
//
//    private static final Logger log = LoggerFactory.getLogger(AESUtils.class);
//
//    public static final String KEY_ALGORITHM = "AES";
//    public static final String ENCODING = "utf-8";
//    public static final String KEY = "SYZXjz5otdNNyig/uKXt+w==";
//
//    public static String generateAESKey() {
//        KeyGenerator keyGenerator = null;
//        try {
//            keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM);
//        } catch (NoSuchAlgorithmException e) {
//            return null;
//        }
//        keyGenerator.init(128);
//        SecretKey key = keyGenerator.generateKey();
//        byte[] keyExternal = key.getEncoded();
//        return Base64.encodeBase64String(keyExternal);
//    }
//
//    public static String encrypt(String content, String key) {
//        try {
//            byte[] bytesKey = Base64.decodeBase64(key);
//            SecretKeySpec secretKey = new SecretKeySpec(bytesKey, KEY_ALGORITHM);
//            Cipher cipher = Cipher.getInstance(KEY_ALGORITHM);// 创建密码器
//            byte[] byteContent = content.getBytes(ENCODING);
//            cipher.init(Cipher.ENCRYPT_MODE, secretKey);// 初始化
//            byte[] result = cipher.doFinal(byteContent);// 加密
//            return Base64.encodeBase64String(result);
//        } catch (Exception e) {
//            log.error("encrypt error", e);
//        }
//        return null;
//    }
//
//    public static String decrypt(String content, String key) {
//        try {
//            byte[] bytesKey = Base64.decodeBase64(key);
//            SecretKeySpec secretKey = new SecretKeySpec(bytesKey, KEY_ALGORITHM);
//            Cipher cipher = Cipher.getInstance(KEY_ALGORITHM);// 创建密码器
//            cipher.init(Cipher.DECRYPT_MODE, secretKey);// 初始化
//            byte[] result = cipher.doFinal(Base64.decodeBase64(content));// 解密
//            return new String(result);
//        } catch (Exception e) {
//            log.error("decrypt error", e);
//        }
//        return null;
//    }
//
//    public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
////        JSONObject message = new JSONObject();
////        message.put("orderNo", "FSD203108011140605800001890001");
////        message.put("companyName", "杭州微风企科技有限公司");
////
////        String content = message.toJSONString();
////        String key = generateAESKey();
////        key = KEY;
////        log.info("key：" + key);
////        log.info("加密前：" + content);
////        // 加密
////        String encryptResult = encrypt(content, key);
////        log.info("加密后：" + encryptResult);
////
////        String encryptResultBase64 = new String (Base64.encodeBase64(encryptResult.getBytes()), ENCODING);
////        log.info("base64后：" + encryptResultBase64);
////
////        log.info("URL：http://xxxxxx?message={}" , URLEncoder.encode(encryptResultBase64) );
////
////        // 解密
////        String decryptResult = decrypt(new String (Base64.decodeBase64(encryptResultBase64.getBytes()), ENCODING ), key);
////        log.info("解密后：" + new String(decryptResult));
//
//
//        //user_id
//        Map<String, Object> userIdMap = new HashMap<>();
//        userIdMap.put("interfaceCode","3d9a9a48e2994636a8df32bbe3109bfdHAZDS");
//        userIdMap.put("secretKey","0U0kw5EFUJSRdxXeQPOU6WTLql1yjjeflLL2xdOJ495DDYYzDEsYU1ahBH947DnG");
//        userIdMap.put("remain_times","1");
//        userIdMap.put("expire_time_hour","1");
//        String userIdJson = new Gson().toJson(userIdMap);
////        String userIdJson = "{\"remain_times\":1,\"secretKey\":\"0U0kw5EFUJSRdxXeQPOU6WTLql1yjjeflLL2xdOJ495DDYYzDEsYU1ahBH947DnG\",\"expire_time_hour\":1,\"interfaceCode\":\"3d9a9a48e2994636a8df32bbe3109bfdHAZDS\"}";
//        log.info("user_id请求参数："+userIdJson);
//        OkHttpClient client = new OkHttpClient();
//        Request userIdRequest = new Request.Builder()
//                .url("https://api.wfq2020.com/mini-program-index-api/accounts/authorize_url_ids")
////                .header("Content-Type", "application/json")
//                .post(RequestBody.create(MediaType.parse("application/json"), userIdJson))
//                .build();
//
//        try {
//            Response response = client.newCall(userIdRequest).execute();
//            if (response.isSuccessful()) {
//                String responseBody = response.body().string();
//                System.out.println("请求成功，结果：" + responseBody);
//            } else {
//                System.out.println("请求失败，结果：" + response.code());
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        // json入参
//    }
//}
